import { fromJS } from 'immutable';
import * as constants from './constants';
import Utils from '../../../common/utils'

const defaultState = fromJS({
	searchList: [],
	login: Utils.local('userData') ? Utils.local('userData'): '',
	sms: 0,
	showType: 'login',
	search: '',
	cartList: {
		list: [],
		schoolList: [],
		total_price: 0
	},
	showLogin: false,
	smsCount: 0
});

export default (state = defaultState, action) => {
	switch(action.type) {
		case constants.CHANGE_LOGIN:
			return state.set('login', action.value)
		case constants.CHANGE_SMS:
			return state.set('sms', action.value)
		case constants.CHANGE_SMSCOUNT:
			return state.set('smsCount', action.value)
		case constants.CHANGE_SHOWTYPE:
			return state.set('showType', action.value)
		case constants.CHANGE_CARTLIST:
			return state.set('cartList', action.value)
		case constants.CHANGE_SEARCH:
				return state.set('search', action.value)
		case constants.CHANGE_SHOWLOGIN:
				return state.set('showLogin', action.value)
		default:
			return state;
	}
}